package com.gu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gu.entity.TOrder;
import com.gu.entity.vo.OrderVo;
import com.gu.service.TOrderService;
import entity.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Description:订单控件
 *
 * @Autor: Rolin
 * datetime: 06-20-14:25
 */
@RestController
@Api(tags = "前台订单控件")
@CrossOrigin
@RequestMapping("/eduOrder")
public class OrderController {

    @Resource
    private TOrderService orderService;

    @ApiOperation("生成订单")
    @PostMapping("/front/createOrderNo/{courseId}/{memberId}")
    public CommonResult createOrderNo(@PathVariable("courseId") String courseId,  @PathVariable("memberId") String memberId  ) {
        OrderVo orderVo = orderService.createOrderNo(courseId, memberId);
        return !StringUtils.isEmpty(orderVo.getOrderNo())? CommonResult.success().data("orderVo",orderVo):CommonResult.error();
    }

    @PostMapping("/front/pay/{orderNo}")
    @ApiOperation("支付订单")
    public CommonResult pay(@PathVariable("orderNo") String orderNo){
        QueryWrapper<TOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("order_no",orderNo);
        TOrder tOrder = new TOrder();
        byte c = 1 ;
        tOrder.setStatus(c);
        boolean update = orderService.update(tOrder, wrapper);
        return update ? CommonResult.success() : CommonResult.error();
    }


}
